package live.jipiao.dao;

import java.util.TreeMap;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;

import live.common.AirParam;
import live.common.Format;
import live.common.Verifystring;

public class QueryOrderStatus {

	/**
	 * 返回订单当前订单状态
	 * 
	 * @param orderNo
	 * @return
	 */
	public String returnOrderStatus(String orderNo) {
		XmlFormart xf = new XmlFormart();
		Verifystring verify = new Verifystring();
		String result = null, resultData = null, is_success = null;
		try {
			TreeMap treemap = xf.returnPublicPostData(AirParam.QUERY_STATUS);
			treemap.put("orderNo", orderNo);
			String sign = verify.returnAirMd5Hex(treemap);
			treemap.put("sign", sign);
			result = WebServicesSub.getInstance().returnResult(treemap);
			if (Format.getInstance().isNotNullOrEmpty(result)) {
				Document doc = xf.xmlToDocument(result);
				is_success = ((Element) doc.selectNodes("//is_success").get(0))
						.getTextTrim();
				if (is_success.equals("T")) {
					resultData = ((Element) doc.selectNodes("//status").get(0))
							.getTextTrim();
					result = resultData.split("\\^")[0];
				}
				if (is_success.equals("F")) {
					resultData = ((Element) doc.selectNodes("//error").get(0))
							.getTextTrim();
					result = null;
				}
			}

		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

}
